#include<bits/stdc++.h>
#define mp(a,b) make_pair(a,b)
#define FILE_NAME "color"
#define fre 1
using namespace std;
typedef long long ll;
ll mx=0;
int n,a[200010],co[200010],c[200010];
void dfs(int dep,bool color,ll ss){
    //color 0:red 1:blue
    if(dep>n){
        ll sum=0;
        for(int i=1;i<=n;i++){
            sum+=c[i];
        }
        mx=max(mx,sum);
        return;
    }
    if(color){
        co[dep]=1;
    }
    for(int i=dep-1;i>=1;i--){
        if(co[i]==co[dep]){
            if(a[i]==a[dep]){
                c[dep]=max(c[dep],a[dep]);
            }
            break;
        }
    }
    dfs(dep+1,0,ss+c[dep]);
    dfs(dep+1,1,ss+c[dep]);
    co[dep]=0;
    c[dep]=0;
}
void solve(){
    mx=0;
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>a[i];
    }
    dfs(0,0,0);
    dfs(0,1,0);
    cout<<mx<<endl;
}
int main(){
#ifdef fre
    freopen(FILE_NAME ".in","r",stdin);
    freopen(FILE_NAME ".out","w",stdout);
#endif
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int T;
    cin>>T;
    while(T--){
        solve();
    }
#ifdef fre
    fclose(stdin);
    fclose(stdout);
#endif
    return 0;
}